package org.pictual.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.pictual.business.vo.CompletoVO;
import org.pictual.controller.mainPackage.Language;
import org.pictual.service.PictualDelegateFactory;
import org.pictual.util.PalabraEnTabla;
import org.pictual.util.SessionKeys;

public class ListadoAction extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
	
		HttpSession sesion= request.getSession();
		
		List<PalabraEnTabla> listadoPalabras = new ArrayList<PalabraEnTabla>();
		String order = request.getParameter("order");
		String wiki = request.getParameter("lang");
		String images = request.getParameter("images");
				
		List<CompletoVO> listado = PictualDelegateFactory.getIdiomaDelegate().selectListado(wiki, order, images);
		
		PalabraEnTabla pet;
		boolean haveImage;
		
		for(CompletoVO completo: listado){
			
//			haveImage = PictualDelegateFactory.getPalabraDelegate().haveImages(completo.getId());
			
			pet = new PalabraEnTabla(
					completo.getPalabra(),
					Language.resolve(completo.getIdioma()), 
					Language.resolve(completo.getWiki()), 
					false, 
					completo.getId().intValue());
			
			listadoPalabras.add(pet);
			
		}
		
		sesion.setAttribute(SessionKeys.WORDS, listadoPalabras);
		
		return mapping.findForward("success");
	}
}
